package com;

import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.webapp.WebAppContext;

/**
 * 项目启动
 * 
 */

public class BootStrap {
	private static Server server;

	public static void main(String[] args) throws Exception {

		server = new Server();
		QueuedThreadPool threadPool = new QueuedThreadPool();
		server.setThreadPool(threadPool);
		Connector connector = new SelectChannelConnector();
		connector.setPort(9085);
		server.setConnectors(new Connector[] { connector });
		connector.setRequestHeaderSize(1024 * 1024 * 10);
		WebAppContext context = new WebAppContext("WebRoot/", "/");
		server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", "-1");
		server.setAttribute("org.mortbay.util.URI.charset", "utf-8");
		context.setMaxFormContentSize(-1);
		server.setHandler(context);
		server.setStopAtShutdown(true);
		server.setSendServerVersion(false);

		// Fix for Windows, so Jetty doesn't lock files
		if (System.getProperty("os.name").toLowerCase().contains("windows")) {
			context.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
		}

		server.start();
		server.join();

	}

	public static void shutdown() {
		try {
			server.stop();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}